<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}

// 获取表模型
$table_er_kami_log = C::t('#erling_kami_apibuy#er_kami_apibuy_log');

$url_page = ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=erling_kami_apibuy&pmod=admin_kami_apibuy_log';

// 获取当前列表
$page = max(1, intval($page));
$pagesize = max($_GET['pagesize']??20, intval($pagesize));
$start = ($page - 1) * $pagesize;

$query = [];
if(!empty($_GET['id'])){
    $query['id'] = intval($_GET['id']);
    $url_page .= '&id='.$_GET['id'];
}
if(!empty($_GET['uid'])){
    $query['uid'] = intval($_GET['uid']);
    $url_page .= '&uid='.$_GET['uid'];
}
if(!empty($_GET['title'])){
    $query['title'] = trim($_GET['title']);
    $url_page.= '&title='.urlencode($_GET['title']);
}
if(!empty($_GET['kami_key'])){
    $query['kami_key'] = trim($_GET['kami_key']);
    $url_page.= '&kami_key='.urlencode($_GET['kami_key']);
}
if(!empty($_GET['order_no'])){
    $query['order_no'] = trim($_GET['order_no']);
    $url_page.= '&order_no='.urlencode($_GET['order_no']);
}
if(!empty($_GET['is_api'])){
    $query['is_api'] = intval($_GET['is_api']);
    $url_page.= '&is_api='.$_GET['is_api'];
}
if(!empty($_GET['api_domain'])){
    $query['api_domain'] = trim($_GET['api_domain']);
    $url_page.= '&api_domain='.urlencode($_GET['api_domain']);
}
if(!empty($_GET['expire_time'])){
    $url_page .= '&expire_time='.$_GET['expire_time'];
}
$result = $table_er_kami_log->fetch_all($page, $pagesize, $query, $expire_time);
$kami_list = $result['data'];
$total = $result['total'];

if(!empty($_GET['pagesize'])){
    $url_page .= '&pagesize='.intval($_GET['pagesize']);
}
$multipage = multi($total, $pagesize, $page, $url_page);

// 积分类型
$extcredits_array = DB::fetch_all("SELECT * FROM %t WHERE skey LIKE %s", array('common_setting', 'extcredits%'));
if ($extcredits_array && isset($extcredits_array[0]['svalue'])) {
    $extcredits_data = unserialize($extcredits_array[0]['svalue']);
} else {
    $extcredits_data = [];
}


include template('erling_kami_apibuy:admin_kami_apibuy_log');